﻿//
//  ProblemFactory.cs
//
//  Author:
//       Antonio J. Nebro <antonio@lcc.uma.es>
//
//  Copyright (c) 2011 Antonio J. Nebro
//
//  This program is free software: you can redistribute it and/or modify
//  it under the terms of the GNU Lesser General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU Lesser General Public License for more details.
// 
//  You should have received a copy of the GNU Lesser General Public License
//  along with this program.  If not, see <http://www.gnu.org/licenses/>.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

using jmetal.core;

namespace jmetal.problems
{
  public class ProblemFactory
  {
    public Problem getProblem (String name, Object parameters)
    {
      string problemName = "jmetal.problems." + name;
      Console.WriteLine ("problem: " + problemName);

      Type type = Type.GetType (problemName);
      Console.WriteLine ("Type: " + type.FullName);

      Type[] types = new Type[1];
      types[0] = typeof(String);

      ConstructorInfo ci = type.GetConstructor (types);
      var problem = ci.Invoke (new object[] { (String)parameters });
       /*
      ConstructorInfo[] ci = type.GetConstructors ();

      Console.WriteLine ("ci.length: " + ci.Length);

      for (int x = 0; x < ci.Length; x++) {
        ParameterInfo[] pi = ci[x].GetParameters ();
        //if (pi.Length == 2)
        //  break;
        Console.WriteLine ("x: " + x);
      }

      Problem problem = (Problem)Activator.CreateInstance (type, (String)parameters) ;
      */
  /*
      ConstructorInfo ci = type.GetConstructor (new Type[] { type });

      var problem = ci.Invoke (new object[] { parameters });
 */

      return (Problem)problem;
    }
  }
}
